var promise = new Promise( function( resolve, reject) { 
    if( ){  //异步操作成功
      resolve(value);
    }else{
      reject(error);
   }
});

promise.then(
    function(value){
        //success成功
    },
    function(error){
        //failure失败
});

function timeOut (ms) {
    return new Promise(function(resolve,reject) {
               return    setTimeout(resolve,ms,"done");
     });
}
timeOut(3000).then( function(value){
    console.log(value);
});

let promise = new Promise(function(resolve, reject) {
    console.log('Promise');
    resolve();
});
  
promise.then(function() {
    console.log('resolved.');
});
  
console.log('Hi!');  
// Promise
// Hi!
// resolved